home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2007 December / PCWKCD1207B.iso / Blogowanie poza sfera / Flock 0.9.1.3 stable / flock-0.9.1.3.en-US.win32.exe / flock / yahootoolbar.xpi / components / nsYahooDomBuilder.js < prev    next >
Text File  |  2007-01-12  |  23KB  |  619 lines

  1. /*
  2.  * Copyright 2005 - 2006 Yahoo! Inc. All rights reserved.
  3.  */
  4. function nsIYahooDomBuilder(){
  5.     try{
  6.         this.gPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  7.         var doc = Components.classes["@mozilla.org/xul/xul-document;1"].createInstance(Components.interfaces.nsIDOMDocument);
  8.         this.document = doc.implementation.createDocument(this.ns, "overlay", null);
  9.         this.toolbarDoc = doc.implementation.createDocument(this.ns, "overlay", null);
  10.         this.toolbarDoc.firstChild.setAttribute("id", "toolbar");
  11.         var str = Components.classes["@mozilla.org/intl/stringbundle;1"].getService(Components.interfaces.nsIStringBundleService);
  12.         this.strings = str.createBundle("chrome://ytoolbar/locale/ytoolbar.properties");
  13.         this.bm2Usage = new Array();
  14.         this.clear();
  15.     } catch(e){
  16.     }
  17. }
  18. nsIYahooDomBuilder.prototype = {
  19.     document : null,
  20.     toolbarDoc : null,
  21.     ns : "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
  22.     toolbar : null,
  23.     menubar : null,
  24.     toolar_context : null,
  25.     page_context : null,
  26.     removables : [],
  27.     bookmarks : null,
  28.     bm2Feed : null,
  29.     bm2Usage : {},
  30.     bm2Prefs : [],
  31.     bm2FolderSave : null,
  32.     bm2FFBMImportCrumb : null,
  33.     strings : null,
  34.     addNode : function(node, parent){
  35.         var dom, popup;
  36.         try{
  37.             var toolbar = false;
  38.             if(parent == null){
  39.                 parent = this.toolbar;
  40.                 toolbar = true;
  41.                 if(node.id == "yahoo-toolbar-cm"){
  42.                     parent = this.toolar_context;
  43.                     toolbar = false;
  44.                 }
  45.                 else if(node.id == "yahoo-toolbar-rmc_m"){
  46.                     parent = this.page_context;
  47.                     toolbar = false;
  48.                 }
  49.                 else if(node.id == "yahoo-toolbar-acs"){
  50.                     this.menubarExtra.appendChild(this.document.createElementNS(this.ns, "menuseparator"));
  51.                     return this.menubarExtra;
  52.                 }
  53.                 else{
  54.                     if(this.toolbar.lastChild.childNodes.length > 0){
  55.                         parent = this.toolbar.lastChild;
  56.                     }            
  57.                     else if(node.type == node.SEPARATOR_TYPE 
  58.                             || (this.toolbar.firstChild.lastChild && this.toolbar.firstChild.lastChild.nodeName == "toolbarseparator")){
  59.                         parent = this.toolbar.lastChild;
  60.                     }
  61.                     else {
  62.                         parent = this.toolbar.firstChild;
  63.                     }
  64.                 }
  65.             }
  66.             else if(parent == this.alerts){
  67.                 toolbar = true;
  68.             }
  69.             if(toolbar){
  70.                 dom = parent.ownerDocument.createElementNS(this.ns, "toolbarbutton");
  71.                 switch(node.type){
  72.                     case node.BUTTON_TYPE:
  73.                     break;
  74.                     case node.BUTTONMENU_TYPE:
  75.                         dom.setAttribute("type", "menu-button");
  76.                         popup = dom.appendChild(parent.ownerDocument.createElementNS(this.ns, "menupopup"));
  77.                     break;
  78.                     case node.MENU_TYPE:
  79.                         dom.setAttribute("type", "menu");
  80.                         popup = dom.appendChild(parent.ownerDocument.createElementNS(this.ns, "menupopup"));
  81.                     break;
  82.                     case node.MENUITEM_TYPE:
  83.                     break;
  84.                     case node.EDITBOX_TYPE:
  85.                         dom = this.buildSearchBox(node);
  86.                     break;
  87.                     case node.SEPARATOR_TYPE:
  88.                         dom = parent.ownerDocument.createElementNS(this.ns, "toolbarseparator");
  89.                     break;
  90.                     default:
  91.                         return null;
  92.                 }
  93.             }
  94.             else{
  95.                 dom = parent.ownerDocument.createElementNS(this.ns, "menuitem");
  96.                 switch(node.type){
  97.                     case node.MENUITEM_TYPE:
  98.                     case node.BUTTON_TYPE:
  99.                     break;
  100.                     case node.BUTTONMENU_TYPE:
  101.                     case node.MENU_TYPE:
  102.                         dom = parent.ownerDocument.createElementNS(this.ns, "menu");
  103.                         popup = dom.appendChild(parent.ownerDocument.createElementNS(this.ns, "menupopup"));
  104.                     break;
  105.                     case node.SEPARATOR_TYPE:
  106.                         dom = parent.ownerDocument.createElementNS(this.ns, "menuseparator");
  107.                     break;
  108.                     case node.EDITBOX_TYPE:
  109.                         return null;
  110.                     break;
  111.                     default:
  112.                         return null;
  113.                 }
  114.             }
  115.             var id = node.id;  
  116.             dom.setAttribute("id",  id);
  117.             dom.setAttribute("label", node.name);
  118.             dom.setAttribute("yhash", node.hash);
  119.             var hash;
  120.             eval("hash = {"+ node.hash +"}")
  121.             if(id == "yahoo-toolbar-boo2_m" && hash.bmfeed){        
  122.                 this.bm2Feed = unescape(hash.bmfeed);
  123.                 if(hash.bmfoldersave){
  124.                     this.bm2FolderSave = unescape(hash.bmfoldersave);
  125.                 }
  126.                 else{
  127.                 }
  128.             }
  129.             if("yahoo-toolbar-boo_m/boo_m_6/boo_m_6_1" == id && hash.bmimport) {
  130.                 if(hash.bmimport) {
  131.                     this.bm2FFBMImportCrumb = unescape(hash.bmimport);
  132.                 }
  133.             }
  134.             if(node.type == node.BUTTON_TYPE || node.type == node.MENUITEM_TYPE || node.type == node.BUTTONMENU_TYPE){
  135.                 if(!dom.hasAttribute("oncommand")){
  136.                     dom.setAttribute("oncommand", "yahooButtonHandler(event);");
  137.                     dom.setAttribute("onclick", "if(event.button == 1) yahooButtonHandler(event);");
  138.                 }
  139.                 dom.setAttribute("yevent", node.func);
  140.                 dom.setAttribute("ytrack", node.funcTracking);
  141.                 dom.setAttribute("yfunc",  node.funcNum);
  142.                 if(node.funcUrl != null && node.funcUrl != ""){
  143.                     dom.setAttribute('yurl', node.funcUrl);
  144.                 }
  145.             }
  146.             if(dom.ownerDocument.firstChild && dom.ownerDocument.firstChild.id == "toolbar"){
  147.                 dom.setAttribute("contextmenu", "yahoo-toolbar-context");
  148.             }
  149.             if(dom.ownerDocument.firstChild && dom.ownerDocument.firstChild.id == "toolbar" && node.funcNum == "1" && parent.parentNod && parent.parentNode.id != "yahoo-toolbar-boo2_m" ){
  150.                 parent.parentNode.setAttribute("id", "yahoo-toolbar-bookmarks-"+ (node.funcTracking || 1));
  151.             }
  152.             if(node.id == "yahoo-toolbar-rss" || node.id == "yahoo-toolbar-rss_m" || node.id == "yahoo-toolbar-RSS"
  153.                 || node.id == "menu_yahoo-toolbar-rss" || node.id == "menu_yahoo-toolbar-rss_m" || node.id == "menu_yahoo-toolbar-RSS"){
  154.                 dom.style.display = "none";
  155.             }
  156.             if(node.id == "yahoo-toolbar-cm-sio"){
  157.                 dom.setAttribute("type", "checkbox");
  158.             }
  159.             dom.setAttribute("class", "yahoo-button-showlabel");
  160.             if(node.icon != null && node.icon != ""){
  161.                 dom.setAttribute("image", node.icon);
  162.                 if(dom.tagName == "menuitem"){
  163.                     dom.setAttribute("class", "menuitem-iconic");
  164.                 }
  165.                 else if(dom.tagName == "menu"){
  166.                     dom.setAttribute("class", "menu-iconic");
  167.                 }
  168.             }
  169.             else if(node.icon == null || node.icon == ""){
  170.                 dom.setAttribute("class", "yahoo-button-noimg");
  171.             }
  172.             if(node.styles.indexOf("NOTEXT") > -1){
  173.                 dom.className = "yahoo-button-notext";
  174.             }
  175.             if(node.styles.indexOf("ALWAYSHIDE") > -1){
  176.                 dom.setAttribute("hidden", true);
  177.             }
  178.             if(node.id != null && node.styles.indexOf("REMOVEONCLICK") > -1){
  179.                 this.removables[this.removables.length] = dom;
  180.             }
  181.             dom.setAttribute("ystyles", node.styles);
  182.             if(dom.ownerDocument.firstChild && dom.ownerDocument.firstChild.id == "toolbar" && node.type != node.EDITBOX_TYPE && node.styles.indexOf("NOTOOLTIP") == -1){
  183.                 dom.setAttribute("tooltiptext", node.name);
  184.                 if(hash.at != null){
  185.                     var tt = "";
  186.                     var tooltip = hash.at;
  187.                     if(tooltip){
  188.                         tooltip = tooltip.replace(/%25/g, "");
  189.                         tooltip = tooltip.replace(/%|\$|,/g, "");
  190.                         dom.setAttribute("tooltiptext", tooltip);
  191.                     }
  192.                 }
  193.             }
  194.             parent.appendChild(dom);
  195.             if(dom.ownerDocument.firstChild && dom.ownerDocument.firstChild.id == "toolbar"){
  196.                 var mdom, mpopup;
  197.                 if(dom.nodeName.indexOf("toolbar") == 0){
  198.                     switch(dom.nodeName){
  199.                         case "toolbarbutton":
  200.                             switch(dom.getAttribute("type")){
  201.                                 case "menu-button":
  202.                                     mdom = this.document.createElementNS(this.ns, "menu");
  203.                                     mpopup = mdom.appendChild(this.document.createElementNS(this.ns, "menupopup"));
  204.                                     mdom.setAttribute("label", node.name);
  205.                                     if(node.id != null){
  206.                                         mdom.setAttribute("id", "menu_"+ node.id);
  207.                                     }
  208.                                     mdom = mpopup.appendChild(this.document.createElementNS(this.ns, "menuitem"));
  209.                                     mpopup.appendChild(this.document.createElementNS(this.ns, "menuseparator"));
  210.                                 break;
  211.                                 case "menu":
  212.                                     mdom = this.document.createElementNS(this.ns, "menu");
  213.                                     mpopup = mdom.appendChild(this.document.createElementNS(this.ns, "menupopup"));
  214.                                 break;
  215.                                 default:
  216.                                     mdom = this.document.createElementNS(this.ns, "menuitem");
  217.                             }
  218.                         break;
  219.                         case "toolbarseparator":
  220.                             mdom = this.document.createElementNS(this.ns, "menuseparator");
  221.                         break;
  222.                     }
  223.                     if(mdom){
  224.                         var attr;
  225.                         for(var i = 0; i < dom.attributes.length; i++){
  226.                             attr = dom.attributes[i];
  227.                             if( attr.name != "id" 
  228.                                     && attr.name != "contextmenu"
  229.                                     && attr.name != "class"
  230.                                     && attr.name != "image"
  231.                                     && attr.name != "tooltiptext"
  232.                                     && attr.name != "type"){
  233.                                 mdom.setAttribute(attr.name, attr.value);
  234.                             }
  235.                         }
  236.                     }
  237.                 }
  238.                 else{
  239.                     mdom = dom.cloneNode(true);
  240.                     if(popup){
  241.                         mpopup = mdom.firstChild;
  242.                     }
  243.                 }
  244.                 if(mdom != null){
  245.                     if(node.id != null){
  246.                         if(node.type == node.BUTTONMENU_TYPE){
  247.                             mdom.setAttribute("id", "menu_"+ node.id +"_btn");
  248.                         }
  249.                         else{
  250.                             mdom.setAttribute("id", "menu_"+ node.id);
  251.                         }
  252.                     }
  253.                     mdom.removeAttribute("class");
  254.                     mdom.removeAttribute("contextmenu");
  255.                     mdom.removeAttribute("tooltiptext");
  256.                     mdom.setAttribute("class", "menuitem-iconic");
  257.                     mdom.style.display = dom.style.display;
  258.                     if(node.type == node.BUTTONMENU_TYPE){
  259.                         mdom = mpopup.parentNode;
  260.                     }
  261.                     if(node.id != null && node.styles.indexOf("REMOVEONCLICK") > -1){
  262.                         this.removables[this.removables.length] = dom;
  263.                     }
  264.                     if(node.parentNode && node.parentNode.domMenubar){
  265.                         node.parentNode.domMenubar.appendChild(mdom);
  266.                     }
  267.                     else{
  268.                         this.menubar.appendChild(mdom);
  269.                     }
  270.                     node.domMenubar = mpopup || mdom;
  271.                 }
  272.             }
  273.         } catch(e){
  274.         }
  275.         if(popup != null){
  276.             dom = popup;
  277.         }
  278.         mdom = null;
  279.         mpopup = null;
  280.         popup = null;
  281.         node = null;
  282.         return dom;
  283.     },
  284.     buildSearchBox : function(node){
  285.         var dom = null;
  286.         try{
  287.             dom = this.toolbarDoc.createElementNS(this.ns, "toolbaritem");
  288.             var search = this.toolbarDoc.createElementNS(this.ns, "textbox");
  289.             search.setAttribute("id", "yahooToolbarEditBox");
  290.             search.setAttribute("flex", "1");
  291.             search.setAttribute("size", "4");
  292.             search.setAttribute("minwidth", "55");
  293.             search.setAttribute("sizetopopup", "false");
  294.             search.setAttribute("yevent", node.func);
  295.             search.setAttribute("ytrack", node.funcTracking);
  296.             search.setAttribute("yfunc",  node.funcNum);
  297.             search.setAttribute('onkeyup', "if(event.keyCode == event.DOM_VK_ENTER || event.keyCode == event.DOM_VK_RETURN){ this.blurred(event, true); yahooButtonHandler(event); }");
  298.             if(Components.interfaces.nsIXULAppInfo){
  299.                 var app = Components.classes["@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULAppInfo);
  300.                 if(app && parseFloat(app.version) >= 1.5){
  301.                     search.setAttribute("class", "yahoo-toolbar-search-live");
  302.                     search.setAttribute("autocompletepopup", "yahooToolbarEditBox-history");
  303.                     search.setAttribute("enablehistory", "true");
  304.                     search.setAttribute('onkeyup', "yahooUpdateSearchHistory(this, null, event);");
  305.                     var searchHash;
  306.                     eval("searchHash = { "+ node.hash +"}");
  307.                     if(searchHash.live){
  308.                         this.gPrefs.setBoolPref("yahoo.supports.livesearch", true);
  309.                         search.setAttribute("ylive",  unescape(searchHash.live));
  310.                     }
  311.                     else{
  312.                         this.gPrefs.setBoolPref("yahoo.supports.livesearch", false);
  313.                         search.setAttribute("ylive",  "");
  314.                     }
  315.                 }
  316.             }
  317.             search.yselect = true;
  318.             search.setAttribute("onmousedown", "this.yselect = !this.hasAttribute('focused')");
  319.             search.setAttribute("onclick", "if(this.yselect){ this.select(); }");
  320.             var splitter = this.toolbarDoc.createElementNS(this.ns, "splitter");
  321.             splitter.id = "yahoo-toolbar-splitter";
  322.             splitter.setAttribute("resizebefore", "grow");
  323.             splitter.setAttribute("resizeafter", "grow");
  324.             splitter.setAttribute("onmouseup", "yahooSplitterResize()");
  325.             splitter.setAttribute("onclick", "yahooSetSearchboxSize()");
  326.             var hbox = this.toolbarDoc.createElementNS(this.ns, "hbox");
  327.             hbox.setAttribute("flex", "1");
  328.             dom.appendChild(search);
  329.             dom.appendChild(splitter);
  330.             dom.appendChild(hbox);
  331.         } catch(e){ 
  332.         }
  333.         return dom;
  334.     },
  335.     clear : function(){
  336.         try{
  337.             this.removables = [];
  338.             this.toolbar = null;
  339.             this.menubar = null;
  340.             this.menubarExtra = null;
  341.             this.toolar_context = null;
  342.             this.page_context = null;
  343.             this.alerts = null;
  344.             this.toolbar = this.toolbarDoc.createDocumentFragment();
  345.             this.menubar = this.document.createDocumentFragment();
  346.             this.menubarExtra = this.document.createDocumentFragment();
  347.             this.toolar_context = this.document.createDocumentFragment();
  348.             this.page_context = this.document.createDocumentFragment();
  349.             this.alerts = this.document.createDocumentFragment();
  350.             this.toolbar.appendChild(this.toolbarDoc.createElementNS(this.ns, "hbox"));
  351.             this.toolbar.appendChild(this.toolbarDoc.createElementNS(this.ns, "hbox"));
  352.             this.toolbar.firstChild.id = "yahoo-toolbar-reqbtns";
  353.             this.toolbar.lastChild.id = "yahoo-toolbar-btns";
  354.         } catch(e){
  355.         }
  356.     },
  357.     remove : function(id){
  358.         try{
  359.             var nId;
  360.             for(var i = 0; i < this.removables.length; i++){
  361.                 if(this.removables[i] != null && this.removables[i].parentNode != null 
  362.                         && (this.removables[i].id == id || this.removables[i].id == "menu_"+ id || this.removables[i].id == "menu_"+ id +"_btn")){
  363.                     this.removables[i].parentNode.removeChild(this.removables[i]);
  364.                     this.removables[i] = null;
  365.                 }
  366.             }
  367.         } catch(e){
  368.         }
  369.     },
  370.     clearBM2 : function(){
  371.         try{
  372.             this.bookmarks = null;
  373.             this.bookmarks = this.document.createDocumentFragment();
  374.         } catch(e){
  375.         }
  376.     },
  377.     buildBM2 : function(dom, parent){
  378.         try{
  379.             if(!parent){
  380.                 parent = this.bookmarks;
  381.             }
  382.             var uni = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
  383.             uni.charset = "utf-8";
  384.             var node, name, type, url, menu, menupopup, menuitem, str;
  385.             for(var i = 0; i < dom.childNodes.length; i++){
  386.                 node = dom.childNodes[i];
  387.                 if(node.nodeName != "outline"){
  388.                     continue;
  389.                 }
  390.                 type = node.getAttribute("type");
  391.                 url = node.getAttribute("u");
  392.                 name = uni.ConvertToUnicode(node.getAttribute("text"));
  393.                 switch(type){
  394.                     case "F":
  395.                         if(node.getAttribute("text") == "root" && node.parentNode && node.parentNode.getAttribute("type") == "ResultSet"){
  396.                             this.buildBM2(node, parent);
  397.                         }
  398.                         else if(node.getAttribute("text") == "tags" && this.bm2Prefs.DisplayFoldersAs == "TagView" && node.getAttribute("fid") == "-1"){
  399.                             this.buildBM2(node, parent);
  400.                         }
  401.                         else{
  402.                             menu = this.document.createElementNS(this.ns, "menu");
  403.                             menu.setAttribute("crop", "end");
  404.                             menu.setAttribute("label", name);
  405.                             menu.setAttribute("tooltiptext", name);
  406.                             menu.setAttribute("onclick", "if(event.button == 1) {yahooBookmarksOpenAll(this.firstChild); yahooButtonHandler(event);}");
  407.                             menupopup = this.document.createElementNS(this.ns, "menupopup");
  408.                             if(this.bm2FolderSave){
  409.                                 str = this.getStr("yahoo.bookmarks.folder.add", "Add page to '__TITLE__'").replace("__TITLE__", name);
  410.                                 menuitem = this.document.createElementNS(this.ns, "menuitem");
  411.                                 menuitem.setAttribute("crop", "end");
  412.                                 menuitem.setAttribute("label", str);
  413.                                 menuitem.setAttribute("tooltiptext", str);
  414.                                 menupopup.appendChild(menuitem);
  415.                                 menupopup.appendChild(this.document.createElementNS(this.ns, "menuseparator"));
  416.                                 var func = this.bm2FolderSave;
  417.                                 menuitem.setAttribute("yevent", this.bm2FolderSave.replace("__FOLDERID__", node.getAttribute("fid")) );
  418.                                 menuitem.setAttribute("oncommand", "yahooButtonHandler(event);");
  419.                             }
  420.                             this.buildBM2(node, menupopup);
  421.                             str = this.getStr("yahoo.bookmarks.folder.open", "Open in Tabs").replace("__TITLE__", name);
  422.                             menupopup.appendChild(this.document.createElementNS(this.ns, "menuseparator"));
  423.                             menuitem = this.document.createElementNS(this.ns, "menuitem");
  424.                             menuitem.setAttribute("crop", "end");
  425.                             menuitem.setAttribute("label", str);
  426.                             menuitem.setAttribute("tooltiptext", str);
  427.                             menuitem.setAttribute("oncommand", "yahooBookmarksOpenAll(this.parentNode);");
  428.                             menuitem.setAttribute("onclick", "if(event.button == 1) yahooButtonHandler(event);");
  429.                             menupopup.appendChild(menuitem);
  430.                             menu.appendChild(menupopup);
  431.                             parent.appendChild(menu);
  432.                         }
  433.                     break;
  434.                     case "B":
  435.                         if((node.parentNode.getAttribute("type") == "RecentSave" || node.parentNode.getAttribute("type") == "FrequentUse")
  436.                             && ( (node.parentNode.getAttribute("type") == this.bm2Prefs.OrderBy && parent.childNodes.length - 1 == this.bm2Prefs.ToolbarDisplay) 
  437.                                 || parent.childNodes.length == this.bm2Prefs.ToolbarDisplay)){
  438.                             break;
  439.                         }
  440.                         menuitem = this.document.createElementNS(this.ns, "menuitem");
  441.                         menuitem.setAttribute("crop", "end");
  442.                         menuitem.setAttribute("label", name);
  443.                         menuitem.setAttribute("value", node.getAttribute("u"));
  444.                         menuitem.setAttribute("contextmenu", "yahoo-toolbar-context");
  445.                         menuitem.setAttribute("tooltiptext", name);
  446.                         menuitem.setAttribute("maxwidth", "300px");
  447.                         url = url.replace(/,/g, "%2C"); 
  448.                         menuitem.setAttribute("yevent", ",4,boo_m,%"+ url);
  449.                         menuitem.setAttribute("ytrack", "boo_m");
  450.                         menuitem.setAttribute("yfunc",  "4");
  451.                         menuitem.setAttribute('yurl', url);
  452.                         menuitem.setAttribute('ybid', node.getAttribute("bid"));
  453.                         menuitem.setAttribute("oncommand", "yahooButtonHandler(event);");
  454.                         menuitem.setAttribute("onclick", "if(event.button == 1) yahooButtonHandler(event);");
  455.                         parent.appendChild(menuitem);
  456.                     break;
  457.                     case "Toolbar":
  458.                         var d;
  459.                         for(var n = 0; n < node.childNodes.length; n++){
  460.                             d = node.childNodes[n];
  461.                             if(d.nodeName == "outline" && d.getAttribute("type") == "Pref"){
  462.                                 this.bm2Prefs[d.getAttribute("text")] = d.getAttribute("a");
  463.                             }
  464.                         }
  465.                     break;
  466.                     case "RecentSave":
  467.                         if(this.bm2Prefs.ToolbarDisplay == 0 || node.getAttribute("total") == "0"){
  468.                             break;
  469.                         }
  470.                         if(this.bm2Prefs.OrderBy == "RecentlySaved"){
  471.                             var frag = this.document.createDocumentFragment()
  472.                             frag.appendChild(this.document.createElementNS(this.ns, "menuitem"));
  473.                             frag.lastChild.setAttribute("label", this.getStr("yahoo.bookmarks.quick.recent", "Recently Saved"));                            
  474.                             frag.lastChild.setAttribute("tooltiptext", this.getStr("yahoo.bookmarks.quick.recent", "Recently Saved"));
  475.                             frag.lastChild.style.fontWeight = "bold";
  476.                             this.buildBM2(node, frag);
  477.                             var sep = this.document.createElementNS(this.ns, "menuseparator");
  478.                             sep.setAttribute("id", "yahoo-bookmarks-quickaccess-separator");
  479.                             if(parent.qaFolder){
  480.                                 parent.insertBefore(frag, parent.qaFolder);
  481.                                 parent.insertBefore(sep, parent.qaFolder);
  482.                                 parent.qaFolder = null;
  483.                             }
  484.                             else{
  485.                                 parent.appendChild(frag);
  486.                                 parent.appendChild(sep);
  487.                             }
  488.                         }
  489.                         else{
  490.                             menu = this.document.createElementNS(this.ns, "menu");
  491.                             menu.setAttribute("id", "yahoo-bookmarks-quickaccess-folder");
  492.                             menu.setAttribute("label", this.getStr("yahoo.bookmarks.quick.recent", "Recently Saved"));
  493.                             menu.setAttribute("tooltiptext", this.getStr("yahoo.bookmarks.quick.recent", "Recently Saved"));
  494.                             menupopup = this.document.createElementNS(this.ns, "menupopup");
  495.                             this.buildBM2(node, menupopup);
  496.                             menu.appendChild(menupopup);
  497.                             parent.appendChild(menu);    
  498.                             parent.qaFolder = menu;                        
  499.                         }
  500.                     break;
  501.                     case "FrequentUse":
  502.                         if(this.bm2Prefs.ToolbarDisplay == 0 || node.getAttribute("total") == "0"){
  503.                             break;
  504.                         }
  505.                         if(this.bm2Prefs.OrderBy == "FrequentlyAccessed"){
  506.                             var frag = this.document.createDocumentFragment()
  507.                             frag.appendChild(this.document.createElementNS(this.ns, "menuitem"));
  508.                             frag.lastChild.setAttribute("label", this.getStr("yahoo.bookmarks.quick.frequent", "Frequently Used"));
  509.                             frag.lastChild.setAttribute("tooltiptext", this.getStr("yahoo.bookmarks.quick.frequent", "Frequently Used"));
  510.                             frag.lastChild.style.fontWeight = "bold";
  511.                             this.buildBM2(node, frag);
  512.                             var sep = this.document.createElementNS(this.ns, "menuseparator");
  513.                             sep.setAttribute("id", "yahoo-bookmarks-quickaccess-separator");
  514.                             if(parent.qaFolder){
  515.                                 parent.insertBefore(frag, parent.qaFolder);
  516.                                 parent.insertBefore(sep, parent.qaFolder);
  517.                                 parent.qaFolder = null;
  518.                             }
  519.                             else{
  520.                                 parent.appendChild(frag);
  521.                                 parent.appendChild(sep);
  522.                             }
  523.                         }
  524.                         else{
  525.                             menu = this.document.createElementNS(this.ns, "menu");
  526.                             menu.setAttribute("id", "yahoo-bookmarks-quickaccess-folder");
  527.                             menu.setAttribute("label", this.getStr("yahoo.bookmarks.quick.frequent", "Frequently Used"));
  528.                             menu.setAttribute("tooltiptext", this.getStr("yahoo.bookmarks.quick.frequent", "Frequently Used"));
  529.                             menupopup = this.document.createElementNS(this.ns, "menupopup");
  530.                             this.buildBM2(node, menupopup);
  531.                             menu.appendChild(menupopup);
  532.                             parent.appendChild(menu);
  533.                             parent.qaFolder = menu;
  534.                         }
  535.                     break;
  536.                 }
  537.             }            
  538.             uni = null;
  539.         } catch(e){
  540.         }
  541.     },
  542.     bumpUpBM2Usage : function(bid) {
  543.         if(null == bid || "" == bid)
  544.             return;
  545.         var cnt = 1;
  546.         if(null != this.bm2Usage[bid])
  547.         {
  548.             cnt = parseInt(this.bm2Usage[bid]);
  549.             cnt = (cnt < 1 ? 0 : cnt) + 1;
  550.         }
  551.         this.bm2Usage[bid] = "" + cnt;
  552.     },
  553.     getBM2UsageString : function() {
  554.         var str = "";
  555.         for(key in this.bm2Usage) {
  556.             if(null != key && "" != key) {
  557.                 str += (str.length < 1 ? "" : ",") 
  558.                     + key + "|" + this.bm2Usage[key];
  559.             }
  560.         }
  561.         return str;
  562.     },
  563.     clearBM2Usage : function() {
  564.         for(key in this.bm2Usage) {
  565.             this.bm2Usage[key] = null;
  566.         }
  567.         this.bm2Usage = new Array();
  568.     },
  569.     getStr : function(name, def){
  570.         var str = null;
  571.         if(this.strings){
  572.             str = this.strings.GetStringFromName(name);
  573.         }
  574.         if(!str && def){
  575.             return def;
  576.         }
  577.         return str;
  578.     },
  579.     debug : function(msg){
  580.         if(typeof(Components.interfaces.nsIDebugLoggerManager) != 'undefined'){
  581.             logMngr = Components.classes["@mozmonkey.com/debuglogger/manager;1"].getService(Components.interfaces.nsIDebugLoggerManager);
  582.             logger = logMngr.registerLogger("yfeedtest");
  583.             logger.log(3, msg);
  584.         }
  585.     },
  586.     QueryInterface: function (iid) {
  587.         if(!iid.equals(Components.interfaces.nsIYahooDomBuilder) && !iid.equals(Components.interfaces.nsISupports))
  588.             throw Components.results.NS_ERROR_NO_INTERFACE;
  589.         return this;
  590.     }
  591. };
  592. function NSGetModule(compMgr, fileSpec) {
  593.     return {
  594.         myCID         : Components.ID("{15e84d13-9bda-4810-ad02-437d2580c87d}"),
  595.         myProgID     : "@yahoo.com/dombuilder;1",
  596.         firstTime    : true,
  597.         registerSelf : function (compMgr, fileSpec, location, type) {
  598.             if (this.firstTime) {
  599.                 this.firstTime = false;
  600.                 throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
  601.             }
  602.             compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  603.             compMgr.registerFactoryLocation(this.myCID, "Yahoo! Dom Builder", this.myProgID, fileSpec, location, type);
  604.         },
  605.         getClassObject : function (compMgr, cid, iid) {
  606.             if (!cid.equals(this.myCID)) throw Components.results.NS_ERROR_NO_INTERFACE;
  607.             if (!iid.equals(Components.interfaces.nsIFactory)) throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  608.             return this.myFactory;
  609.         },
  610.         myFactory : {
  611.             createInstance : function (outer, iid) {
  612.                 if (outer != null) throw Components.results.NS_ERROR_NO_AGGREGATION;
  613.                 return (new nsIYahooDomBuilder()).QueryInterface(iid);
  614.             }
  615.         },
  616.         canUnload : function(compMgr) { return true; }
  617.     };
  618. }
  619.